
//---------------------------------------------------------------------------
#include "importer/pg1_importer.h"
//---------------------------------------------------------------------------
#include "entities/pg1_map.h"
//---------------------------------------------------------------------------
#include "rendering/pg1_renderer.h"
#include "importer/tinyxml2.h"
//---------------------------------------------------------------------------
using namespace pg1;
//---------------------------------------------------------------------------
Importer::Importer ()
{
	// nothing to do
}
//---------------------------------------------------------------------------
Importer::~Importer ()
{
	// nothing to do
}
//---------------------------------------------------------------------------
bool Importer::importMap (Map& rkMap, Renderer& rkRenderer, const std::string& rkFilename)
{
	tinyxml2::XMLDocument kXMLDoc;
	kXMLDoc.LoadFile( rkFilename.c_str() );

	// map info
	tinyxml2::XMLElement* pkMapElement = kXMLDoc.FirstChildElement("map");
	
	unsigned int uiMapWidth = atoi( pkMapElement->Attribute("width") );
	unsigned int uiMapHeight = atoi( pkMapElement->Attribute("height") );

	rkMap.setDimensions(uiMapWidth, uiMapHeight);
	
	unsigned int uiTileWidth = atoi( pkMapElement->Attribute("tilewidth") );
	unsigned int uiTileHeight = atoi( pkMapElement->Attribute("tileheight") );

	rkMap.setTileDimensions(uiTileWidth, uiTileHeight);

	// tiles image path
	tinyxml2::XMLElement* pkTilesetElement = pkMapElement->FirstChildElement("tileset");
	tinyxml2::XMLElement* pkImageElement = pkTilesetElement->FirstChildElement("image");
	
	std::string kImagePath = pkImageElement->Attribute("source");

	rkMap.setTexture( rkRenderer.loadTexture(kImagePath, 0) );

	// add tiles
	

	return true;
}
//---------------------------------------------------------------------------
